package cn.springstudio.springui;

import android.graphics.Color;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.NonNull;

import com.wangjie.rapidfloatingactionbutton.RapidFloatingActionButton;
import com.wangjie.rapidfloatingactionbutton.RapidFloatingActionHelper;
import com.wangjie.rapidfloatingactionbutton.RapidFloatingActionLayout;
import com.wangjie.rapidfloatingactionbutton.contentimpl.labellist.RFACLabelItem;
import com.wangjie.rapidfloatingactionbutton.contentimpl.labellist.RapidFloatingActionContentLabelList;

import java.util.ArrayList;
import java.util.List;

import cn.springstudio.springui.base.ButtonActivity;
import cn.springstudio.springui.base.CheckBoxActivity;
import cn.springstudio.springui.base.EditTextActivity;
import cn.springstudio.springui.base.ImageViewActivity;
import cn.springstudio.springui.base.ProgressBarActivity;
import cn.springstudio.springui.base.RatingBarActivity;
import cn.springstudio.springui.base.SeekBarActivity;
import cn.springstudio.springui.base.SpinnerActivity;
import cn.springstudio.springui.base.TextViewActivity;
import cn.springstudio.springui.template.GridFragment;
import cn.springstudio.springui.template.LayoutDialog;
import cn.springstudio.springui.template.ViewListener;

/**
 * 名称：<b>BaseFragment</b>
 * <p>作者：SpringStudio</p>
 * <p>版本：1.0</p>
 * <p>日期：2021/08/15 8:24</p>
 * <p>说明：</p>
 */
public class BaseFragment extends GridFragment {

    private BaseFragment() {
        addAction("Button", ButtonActivity.class);
        addAction("CheckBox", CheckBoxActivity.class);
        addAction("EditText", EditTextActivity.class);
        addAction("ImageView", ImageViewActivity.class);
        addAction("ProgressBar", ProgressBarActivity.class);
        addAction("RatingBar", RatingBarActivity.class);
        addAction("SeekBar", SeekBarActivity.class);
        addAction("Spinner", SpinnerActivity.class);
        addAction("TextView", TextViewActivity.class);
    }

    public static BaseFragment newInstance() {
        return new BaseFragment();
    }

    @Override
    public void onItemClicked(int position) {
        String name = getItem(position);
        if (name.equals("Button")) {
            LayoutDialog.newInstance(R.layout.ui_rapid_fab, new ViewListener() {

                private RapidFloatingActionLayout rfaLayout;
                private RapidFloatingActionButton rfaBtn;
                private RapidFloatingActionHelper rfabHelper;

                @Override
                public void bindView(@NonNull View view) {
                    rfaLayout = view.findViewById(R.id.activity_main_rfal);
                    rfaBtn = view.findViewById(R.id.activity_main_rfab);
                    RapidFloatingActionContentLabelList rfaContent =
                            new RapidFloatingActionContentLabelList(getContext());
                    rfaContent.setOnRapidFloatingActionContentLabelListListener(new RapidFloatingActionContentLabelList.OnRapidFloatingActionContentLabelListListener() {
                        @Override
                        public void onRFACItemLabelClick(int position, RFACLabelItem item) {
                            Toast.makeText(getContext(), "clicked label: " + position, Toast.LENGTH_SHORT).show();
                            rfabHelper.toggleContent();
                        }

                        @Override
                        public void onRFACItemIconClick(int position, RFACLabelItem item) {
                            Toast.makeText(getContext(), "clicked icon: " + position, Toast.LENGTH_SHORT).show();
                            rfabHelper.toggleContent();
                        }
                    });
                    List<RFACLabelItem> items = new ArrayList<>();
                    items.add(new RFACLabelItem<Integer>()
                            .setLabel("Github: wangjiegulu")
                            .setResId(R.mipmap.ic_launcher)
                            .setIconNormalColor(0xffd84315)
                            .setIconPressedColor(0xffbf360c)
                            .setWrapper(0)
                    );
                    items.add(new RFACLabelItem<Integer>()
                            .setLabel("tiantian.china.2@gmail.com")
                            .setResId(R.mipmap.ic_launcher)
                            .setIconNormalColor(0xff4e342e)
                            .setIconPressedColor(0xff3e2723)
                            .setLabelColor(Color.WHITE)
                            .setLabelSizeSp(14)
                            .setWrapper(1)
                    );
                    items.add(new RFACLabelItem<Integer>()
                            .setLabel("WangJie")
                            .setResId(R.mipmap.ic_launcher)
                            .setIconNormalColor(0xff056f00)
                            .setIconPressedColor(0xff0d5302)
                            .setLabelColor(0xff056f00)
                            .setWrapper(2)
                    );
                    items.add(new RFACLabelItem<Integer>()
                            .setLabel("Compose")
                            .setResId(R.mipmap.ic_launcher)
                            .setIconNormalColor(0xff283593)
                            .setIconPressedColor(0xff1a237e)
                            .setLabelColor(0xff283593)
                            .setWrapper(3)
                    );
                    rfaContent.setItems(items)
                            .setIconShadowRadius(10)
                            .setIconShadowColor(0xff888888)
                            .setIconShadowDy(10);
                    rfabHelper = new RapidFloatingActionHelper(
                            getContext(),
                            rfaLayout,
                            rfaBtn,
                            rfaContent
                    ).build();
                }
            }).show(getChildFragmentManager());
        } else {
            super.onItemClicked(position);
        }
    }
}
